<template>
	<view class="home">
		<!-- 个人信息 -->
		<view class="personBox">
			<view class="personRow">
				<view class="personNrBox">
					<view class="personRank">
						{{userList.rank}}
					</view>
					<view class="personName">
						{{userList.userName}}
					</view>
				</view>
				
				<view class="moreBotton" @click="goEdit">
					<u-button 
					size="mini"
					:plain="true"
					:hairline="true"
					type="primary" 
					shape="circle" 
					text="编辑"></u-button>
				</view>
			</view>
			
			<!-- 用户个性签名 -->
			<view class="signature">
				{{userList.signature}}
			</view>
			
			<!-- 用户信息 -->
			<view class="infoBox">
				<view class="infoItem">
					<view>
						刷题进度:
					</view>
					<view class=".data">
						0%
					</view>
				</view>
			
				<view class="infoItem">
					<view>
						正确率:
					</view>
					<view class=".data">
						0%
					</view>
				</view>
			</view>
			
			<view class="infoBox">
				<view class="infoItem">
					<view>
						目标院校: 
					</view>
					<view class=".data">
						{{userList.targetUniversity}}
					</view>
				</view>
				
				<view class="infoItem">
					<view>
						刷题数量: 
					</view>
					<view class=".data">
						0
					</view>
				</view>
			</view>
		</view>
	
		<!-- 设置 -->
		<view class="settingBox" @click="goLogin">
			<!-- 设置的图标 -->
			<view class="settinPic" :style="{backgroundImage: `url(${settinPic})`}">
				
			</view>
			
			<view class="settinText">
				设定
			</view>
		</view>
		
		<!-- add -->
		<view class="settingBox" @click="goadd">
			<!-- 设置的图标 -->
			<view class="settinPic" :style="{backgroundImage: `url(${settinPic})`}">
				
			</view>
			
			<view class="settinText">
				add
			</view>
		</view>
		
		<!-- 注销登录 -->
		<view class="settingBox" @click="logout">
			<!-- 设置的图标 -->
			<view class="settinPic" :style="{backgroundImage: `url(${settinPic})`}">
				
			</view>
			
			<view class="settinText">
				注销登录
			</view>
		</view>
	</view>
</template>

<script>
	import {
			store,
			mutations
		} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		data() {
			return {
				userList:[],
				settinPic:"https://7463-tcb-jt4xhf2yawry64k-6chab0059a75-1316606514.tcb.qcloud.la/settingPic.png"
			};
		},
		onReady() {
			this.getUser();
		},
		computed:{
			userInfo() {
				return store.userInfo
			},
			hasLogin(){
				return store.hasLogin
			}
			
		},
		methods:{
			// 获取用户信息
			getUser(){
				uniCloud.callFunction({
					name:"getUserInfo",
					
				}).then(res=>{
					console.log(res);
					this.userList=res.result.data[0];
					
				}).catch(()=>{
					uni.showToast({
						title:"用户信息获取失败",
						icon:'error'
					})
				})
			},
			// 跳转编辑页面
			goEdit(){
				uni.navigateTo({
					url:"/pages/personEdit/personEdit"
				})
			},
			
			// 跳转登录页面
			goLogin(){
				
				uni.navigateTo({
					url:"/uni_modules/uni-id-pages/pages/login/login-withpwd"
				})
			},
			
			//goadd跳转
			goadd(){
				uni.navigateTo({
					url:"/pages/addQuestion/addQuestion"
				})
			},
			
			//注销登录
			logout(){
				uni.showModal({
					title:"是否确认退出?",
					success:res=>{
						console.log(res);
						if(res.confirm){
							mutations.logout()
						}
					}
				})
			},
			//判断页面登录了没
			goLoginPage(){
				if(!this.hasLogin){
					uni.showToast({
						title:"未登录",
						icon:"none"
					})	
					return true;
				}
				return false
			}
		}
	}
</script>

<style lang="scss">
	$textSize: 28rpx;
	$radius:16rpx;
	$nomalMargin:12rpx;
	$nomalColor:#ffffff;

	
	view{
		box-sizing: border-box;
	}
	page{
		background-color: #f8f8f8;
	}
	.personBox{
		display: flex;
		flex-direction: column;
		margin: $nomalMargin;
		background-color: $nomalColor;
		border-radius: $radius;
		border: 2rpx solid #55AAFF;
		
	}
	.personRow{
		display: flex;
		justify-content: space-between;
		padding: 18rpx 12rpx 0 12rpx;
		align-items: center;
		.personNrBox{
			display: flex;
			align-items: center;
			.personRank{
				color: #333333;
				font-size: 32rpx;
				font-weight: bold;
				padding-right: 12rpx;
			}
		}
		.personName{
			color: #333333;
			font-size: 42rpx;
			font-weight: bold;
		}

	}
	
	.moreBotton{
		padding-right: 12rpx;
		width: 100rpx;
		height: 100rpx;
	}
	.signature{
		color: #777777;
		font-size: $textSize;
		padding: 0 12rpx 15rpx;
	}
	
	.infoBox{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 12rpx;
	}
	.infoItem{
		width: 50%;
		display: flex;
		align-items: center;
		text-align: left;
		white-space: nowrap;
		font-size: 28rpx;
		padding-bottom: 12rpx;
		view{
			display: flex;
			align-items: center;
	
		}
		.data{
			align-: center;
			padding: 0 6rpx;
		}
	}
	
	.settingBox{
		display: flex;
		margin: 20rpx 12rpx;
		border-radius: $radius;
		padding: 12rpx 12rpx ;
		background-color: #ffffff;
		align-items: center;
		
		.settinPic{
			width: 42rpx;
			height: 42rpx;
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}
		
		.settinText{
			color: #333333;
			font-size: 38rpx;
			padding-left: 18rpx;
		}
	}
</style>
